package com.reflex;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class ReflexDemo05 {
    public static void main(String[] args) throws Exception {
        // 获取Person的Class对象
        Class<?> aClass = Class.forName("com.reflex.Person");
        Constructor<?> constructor = aClass.getConstructor(String.class, int.class);
        // 获取方法
        Method method = aClass.getMethod("say", String.class);
        // 创建对象
        Object object = constructor.newInstance("张三", 18);
        //调用对象
        method.invoke(object, "你好");


        //
        Method method1 = aClass.getMethod("say", String.class, int.class);
        method1.invoke(object, "你好", 3);
    }
}
